/*  
 *  Nanjing JIYU Technology Co.,Ltd All rights reserved.
 *  Copyright (C) 2022 
 *  ==============================================================
 * 
 *  main.c 
 *    主循环，传送带控制逻辑
 *
 *  --------------------------------------------------------------
 *  
 */

#include "main.h"

#include "status.h"

#include "device.h"
#include "peripheral.h"


#define MAXSPEED  500
  

int main(void)
{
  HAL_Init();                     /* HAL相关功能初始化 */
  system_clock_init();            /* 系统时钟设置与延时功能设置 */

  peripheral_init();              /* MCU外设初始化 */

  while (1)
  {
    
    if (GRAY_S0 == 0)
    {
      delay_ms(1000);
      for (int i=0; i<MAXSPEED; i = i+10)
      {
        motor_transporter_pwm_set(i);
        delay_ms(20);
      }
    }
    
    if (GRAY_S1 == 0)
    {
      for (int i=MAXSPEED; i>20; i = i-10)
      {
        motor_transporter_pwm_set(i);
        delay_ms(18);
      }
      delay_ms(10);
      motor_transporter_pwm_set(0);
    }
    
    if (GRAY_FR == 0)
    {
      delay_ms(2000);
      
      motor_fire_pwm_set(1000);
      delay_ms(100);
      motor_fire_pwm_set(0);
      
      delay_ms(500);
      motor_fire_pwm_set(-100);
      delay_ms(1000);
      motor_fire_pwm_set(0);
    }
    
    delay_ms(50);
  }
}

